package com.lzk.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzk.common.R;
import com.lzk.dto.DishDto;
import com.lzk.pojo.Category;
import com.lzk.pojo.Dish;
import com.lzk.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/dish")
public class DishController {
    @Resource
    private DishService dishService;
    @PostMapping
    @Transactional
    public R<String> addDish(@RequestBody DishDto dishDto){
        return dishService.saveWithFlavor(dishDto);
    }
    @GetMapping("/page")
    @Transactional
    public R<Page<DishDto>> page(int page,int pageSize,String name){
        return dishService.myPage(page,pageSize,name);
    }
    @GetMapping("/{id}")
    public R<DishDto> showDishWhenUpdate(@PathVariable Long id){
        return dishService.showDishWhenUpdate(id);
    }
    @PutMapping
    public R<String> updateWithFlavor(@RequestBody DishDto dishDto){
        return dishService.updateWithFlavor(dishDto);
    }
    @PostMapping("/status/{status}")
    public R<String> SaleByIds(@PathVariable("status") int status,@RequestParam List<Long> ids){
        return dishService.SaleByIds(status,ids);
    }
    @DeleteMapping
    public R<String> deleteById(@RequestParam List<Long> ids){
        return dishService.deleteByIds(ids);
    }
    @GetMapping("/list")
    public R<List<DishDto>> listDish(DishDto dishDto){
        return dishService.listDish(dishDto);
    }
}
